﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.DataVisualization.Charting;

using MusicStore.Domain.Concrete;

namespace MusicStore.Domain.POCO
{
  
  public class MyChart : Chart
  {
    
    public object[][] albumsPerGenre { get; set; }
    public MyChart() {
      this.Height = 500;
      this.Width = 500;
      this.ChartAreas.Add(addChartArea());
    }

    private ChartArea addChartArea()
    {
      ChartArea chartArea = new ChartArea();
      chartArea.BackColor = System.Drawing.Color.White ;

      chartArea.AxisX.IsMarksNextToAxis = true;
      chartArea.AxisX.Title = "Genre";
      chartArea.AxisX.LineColor = System.Drawing.Color.Black;
      chartArea.AxisX.TitleForeColor = System.Drawing.Color.Black;
      chartArea.AxisX.TitleForeColor = System.Drawing.Color.Black;

      chartArea.AxisY.IsMarksNextToAxis = true;
      chartArea.AxisY.Title = "Number of Albums";
      chartArea.AxisY.LineColor = System.Drawing.Color.Black;
      chartArea.AxisY.TitleForeColor = System.Drawing.Color.Black;
      return chartArea;
    }
    public Series addDataSerie(List<Genre> genres, List<Album> albums){
      Series serie = new Series();
      serie.Color = System.Drawing.Color.Black;
      serie.BorderColor = System.Drawing.Color.Red;
      int i = 0;
      int count=0;
      foreach(Genre genre in genres){
        DataPoint dp = new DataPoint();
        dp.XValue = i; 
        foreach( Album album in albums){
          if (album.GenreId == genre.GenreId){
          count++;
          }
        }
        dp.YValues = new Double[]{Convert.ToDouble(count)};
        serie.Points.Add(dp);
        i++;
      }
      return serie;
    }
    public void addDataSerieArray(List<Genre> genres, List<Album> albums)
    {


      int i = 0;
     
      object[][] test = new object[genres.Count][];
      foreach (Genre genre in genres)
      {
        test[i] = nieuweRij(genre.Name, genre.Albums.Count);
          i++;
      }
      albumsPerGenre =  test;
        
        
      
      
        
     
    }
    private object[] nieuweRij(String genreName, int count) {
      return new object[] { genreName, count };

    }
    
  }
}
